package com.hhit.bigscreenbackmanage.service.impl.jjgl;

import com.alibaba.fastjson.JSONObject;
import com.hhit.bigscreenbackmanage.entity.jjgl.TJjglJjzdgzydxj;
import com.hhit.bigscreenbackmanage.entity.jjgl.TJjglSgtYsglssqkyb;
import com.hhit.bigscreenbackmanage.dao.jjgl.TJjglSgtYsglssqkybDao;
import com.hhit.bigscreenbackmanage.service.jjgl.TJjglSgtYsglssqkybService;
import com.hhit.bigscreenbackmanage.util.PageUtil;
import com.hhit.bigscreenbackmanage.vo.jjgl.SgtpsSdYsVO;
import com.hhit.bigscreenbackmanage.vo.jjgl.SgtysVO;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * (TJjglSgtYsglssqkyb)表服务实现类
 *
 * @author makejava
 * @since 2021-07-20 15:38:44
 */
@Service("tJjglSgtYsglssqkybService")
public class TJjglSgtYsglssqkybServiceImpl implements TJjglSgtYsglssqkybService {
    @Resource
    private TJjglSgtYsglssqkybDao tJjglSgtYsglssqkybDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public TJjglSgtYsglssqkyb queryById(String id) {
        return this.tJjglSgtYsglssqkybDao.queryById(id);
    }

    /**
     * 查询多条数据
     *
     * @return 对象列表
     */
    @Override
    public Map<String,Object> queryAllByLimit(JSONObject jsonObject) {
        Map<String,Object> out = new HashMap<>();
        PageUtil page = new PageUtil();
        String pageSize = jsonObject.get("pageSize").toString();
        String pageNo = jsonObject.get("pageNo").toString();
        int count = tJjglSgtYsglssqkybDao.queryAllCount(jsonObject);
        page.pageCount=Integer.parseInt(pageSize);// 每页数
        page.init(count,Integer.parseInt(pageNo));//参数1：总行数，参数2：当前页
        jsonObject.put("rowNum",page.getRowNum());
        jsonObject.put("pageCount",page.getPageCount());
        out.put("page",page);
        out.put("list",tJjglSgtYsglssqkybDao.queryAll(jsonObject));
        return out;
    }

    /**
     * 新增数据
     *
     * @param tJjglSgtYsglssqkyb 实例对象
     * @return 实例对象
     */
    @Override
    public TJjglSgtYsglssqkyb insert(TJjglSgtYsglssqkyb tJjglSgtYsglssqkyb) {
        this.tJjglSgtYsglssqkybDao.insert(tJjglSgtYsglssqkyb);
        return tJjglSgtYsglssqkyb;
    }

    /**
     * 修改数据
     *
     * @param tJjglSgtYsglssqkyb 实例对象
     * @return 实例对象
     */
    @Override
    public TJjglSgtYsglssqkyb update(TJjglSgtYsglssqkyb tJjglSgtYsglssqkyb) {
        this.tJjglSgtYsglssqkybDao.update(tJjglSgtYsglssqkyb);
        return this.queryById(tJjglSgtYsglssqkyb.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.tJjglSgtYsglssqkybDao.deleteById(id) > 0;
    }

    @Override
    public Map<String, Object> getSgtPs(JSONObject jsonObject) {
        Map<String,Object> out = new HashMap<>();
        SgtpsSdYsVO sgtpsSdYs = tJjglSgtYsglssqkybDao.getSgtps_sdYs();
        out.put("sdwc",sgtpsSdYs.getSdwc());
        out.put("sdys",sgtpsSdYs.getSdwc());
        out.put("sdysje",sgtpsSdYs.getSdysje());
        String sgtps_pc = tJjglSgtYsglssqkybDao.getSgtps_pc();
        out.put("sdyspc",sgtps_pc);
//        out.put("xypsjh",tJjglSgtYsglssqkybDao.getSgtps_Xyjh());
        out.put("xypsjh","");
        return out;
    }

    @Override
    public Map<String, Object> getSgtPsYs(JSONObject jsonObject) {
        Map<String,Object> out = new HashMap<>();
        SgtysVO sgtpsSdYs = tJjglSgtYsglssqkybDao.getSgtys();
        out.put("sssgtys", sgtpsSdYs.getSssgtys());
        out.put("shhsgtys", sgtpsSdYs.getShhsgtys());
        out.put("sdyspc", sgtpsSdYs.getSdyspc());
        out.put("psjh", sgtpsSdYs.getSdwc());
        out.put("sdwc", sgtpsSdYs.getSdwc());

        return out;
    }

//    public String getSdyspc(List<TJjglJjzdgzydxj> sgtpsPcList){
//        float out = 0;
//        for (int i = 0; i < sgtpsPcList.size(); i++) {
//            TJjglJjzdgzydxj item = sgtpsPcList.get(i);
//            // 预算金额
//            String sgtysjj = item.getSgtysjj();
//            // 较概算偏差比例
//            String sdysjgsbhl = item.getSdysjgsbhl();
//            if(!StringUtils.isEmpty(sgtysjj) && !StringUtils.isEmpty(sdysjgsbhl) ){
//                String substring = sdysjgsbhl.substring(0, sdysjgsbhl.indexOf("%"));
//                float result = jiSuan(substring);
//                out = out + result;
//            }
//        }
//        float pc = out / sgtpsPcList.size() * 100;
//        DecimalFormat dF = new DecimalFormat("0.00");
//        return dF.format(pc);
//    }

    /**
     * 计算
     * @return
     */
//    public static float jiSuan(String a) {
//        float af = Float.parseFloat(a);
//        float bf = (float) (af * 0.01);
//        return bf;
//    }
}
